package com.intelligentcar.springboot.controller;

import com.intelligentcar.springboot.bean.Proposal;
import com.intelligentcar.springboot.service.ProposaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ProposalController {
    public String State;

    @Autowired
    ProposaService proposaService;


    @RequestMapping("/LookPPP")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list(@RequestBody Proposal proposal) {
        Map map = new HashMap();
        if (proposal.getInput().equals("") || proposal.getInput()==""){
            List<Proposal> list = proposaService.LookLook1(proposal);
            map.put("list", list);
            map.put("total", proposaService.selectProposal());
        }
        for(int i=proposal.getInput().length();--i>=0;) {
            int chr = proposal.getInput().charAt(i);
            if (chr < 48 || chr > 57) {
                List<Proposal> list = proposaService.LookLook1(proposal);
                map.put("list", list);
                map.put("total", proposaService.selectProposal());
            } else {
                List<Proposal> list = proposaService.LookproposalTime(proposal.getInput());
                map.put("list", list);
                map.put("total", proposaService.selectProposal());
            }
        }
        return map;
    }

    //    界面数据展示
    @RequestMapping("/LookProposal")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list() {
        List<Proposal> list = proposaService.LookProposal();
//        System.out.println("213");
//       System.out.println(newsService.selectNews());
        Map map = new HashMap();
        map.put("list", list);
        map.put("total",proposaService.selectProposal());
//        System.out.println(list.get(0).getNewsMessage());
//        System.out.println(list.get(0).getNewsUrl());
//        System.out.println("1111111110000000000000000000000000000000++11111111111111111111");
        return map;
    }

    //   回复投诉操作
    @RequestMapping("/updataInfo")
    @ResponseBody //跳过视图解析器,直接返回数据
    public int updateProposal(@RequestBody Proposal proposal) {

//        System.out.println((news.getId()+"2222222222222"));
//        System.out.println(news.getNewsMessage()+"000000000000000000000000");
//        System.out.println(goods.getGoodsnum());
//        System.out.println(goods.getType());
//        Map<String, Object> map = new HashMap<>();
//        map.put("code", proposaService.updateProposal(proposal));
         State= "已处理";

        int a = proposaService.updateProposal(proposal.getId(),proposal.getUid(),proposal.getProposalMessage(),proposal.getProposalPicture(),
                proposal.getProposalTime(),State,proposal.getResponse());

        return a;
    }
//
//    //新闻公告界面中的删除信息操作
//    @RequestMapping("/delNews")//请求路径
//    @ResponseBody //跳过视图解析器,直接返回数据
//    public String delete(long id){
////        String id1 =intValue(id);;
//        newsService.delete((int) id);
//        System.out.println("id是:"+id);
//        return "success";
//    }
//
//    //新闻公告界面中的新增信息操作
//    @RequestMapping("/add")
//    @ResponseBody //跳过视图解析器,直接返回数据
//    public Map<String, Object> add(@RequestBody News news) {
//
//        System.out.println((news.getId()+"2222222222222"));
//        System.out.println(news.getNewsMessage()+"000000000000000000000000");
////        System.out.println(goods.getGoodsnum());
////        System.out.println(goods.getType());
//        Map<String, Object> map = new HashMap<>();
//        map.put("code", newsService.add(news));
//        return map;
//    }
}
